package zhtt.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import zhtt.example.entry.ServiceInstanceInfo;
import zhtt.example.service.DiscoveryService;

@RestController
@RequestMapping("/gateway/services")
public class ServiceController {

    private final DiscoveryService discoveryService;

    @Autowired
    public ServiceController(DiscoveryService discoveryService) {
        this.discoveryService = discoveryService;
    }

    @GetMapping("/all")
    public Flux<String> getServiceNames() {
        return discoveryService.getServiceNames();
    }

    @GetMapping("/{serviceName}/instances")
    public Flux<ServiceInstanceInfo> getServiceInstances(@PathVariable String serviceName) {
        return discoveryService.getServiceInstances(serviceName);
    }
}
